﻿using System;
using System.Collections.Generic;
using System.Text;
using KaiXin001er.Objects;
using KaiXin001er.UTIL;
using KaiXin001er.WebBrowser;

namespace KaiXin001er.Logic
{
    /// <summary>
    /// 整个游戏的思想如下
    /// 进入每一个功能组件都有三个步骤
    /// 1 登陆
    /// 2 游戏
    /// 3 登出
    /// 游戏将分为一个总角色和各个组件的角色
    /// 总角色负责登陆 和调用其它角色执行游戏
    /// 总角色负责登陆 和 初始用户信息
    /// 其它角色负责游戏和读取相关组建信息 
    /// 其它角色也会包括用户角色之类的
    /// </summary>
    public abstract class BasePlayer : EventProvider
    {
        public WebAccessor dac = WebAccessor.Instance;
        private bool _isLogin = false;

        public bool IsLogin
        {
            get { return _isLogin; }
            set { _isLogin = value; }
        }
        
        private string _lastVerify;

        public string LastVerify
        {
            get { return _lastVerify; }
            set { _lastVerify = value; }
        }
        private Account _acct;

        public Account Account
        {
            get { return _acct; }
            set { _acct = value; }
        }

        public BasePlayer(Account acct)
        {
            this._acct=acct;
        }
        public string PlayerID
        {
            get { return _acct.PlayerID; }
            set { _acct.PlayerID = value; }
        }
        public string VerifyCode
        {
            get { return _acct.VerifyCode; }
            set { _acct.VerifyCode = value; }
        }
        public string Email
        {
            get { return _acct.AcctEmail; }
        }
        public string Password
        {
            get { return _acct.AcctPassword; }
        }
        public string Name
        {
            get { return _acct.AcctName; }
        }
        public List<Friend> Friends
        {
            get { return _acct.Friends; }
        }
        public List<string> Components
        {
            get { return _acct.Components; }
        }

        public bool HasFriend(string id)
        {
            return _acct.HasFriend(id);
        }
        public Friend FindFriendByID(string id)
        {
            return _acct.FindFriendByID(id);
        }
        /// <summary>
        /// 登陆
        /// </summary>
        /// <returns></returns>
        public abstract bool SignOn();
        /// <summary>
        /// 登出
        /// </summary>
        /// <returns></returns>
        public abstract bool SignOff();
        /// <summary>
        /// 执行游戏操作
        /// </summary>
        /// <returns></returns>
        public abstract bool PlayPlay();
        public void updateLastVerify(string str)
        {
            int pos = 0;
            this._lastVerify = StringHelper.getMiddleString("verify=","\"",str,ref pos);
            if (_lastVerify == null)_lastVerify= StringHelper.getMiddleString("verify=", "&amp;", str, ref pos);
            if (_lastVerify == null) _lastVerify=StringHelper.getMiddleString("var g_verify = \"", "\";", str);
            _lastVerify = "";
        }
    }
}
